package com.bl.student.dao.repository;

import com.bl.student.dao.model.RoomEntity;
import com.bl.student.dao.model.UserEntity;
import com.bl.student.dao.model.UserRecordEntity;
import com.bl.student.dao.model.UserShareEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

/**
 * Created by liangweikang on 20/6/27.
 */
public interface RecordRepository extends PagingAndSortingRepository<UserRecordEntity, Integer> {

    List<UserRecordEntity> findByUserId(int userId);

    UserRecordEntity findByRecordId(String recordId);

    Page<UserRecordEntity> findByOrderByCreateTime(Pageable pageable);

    List<UserRecordEntity> findByUserIdOrderByWeight(int userId);

    List<UserRecordEntity> findByTrainAndTypeLike(int train, String type);

    void deleteByUserIdAndUserRecordId(int userId ,int userRecordId);

    void deleteByUserId(int userId);

    List<UserRecordEntity> findByUserIdAndUserRecordId(int userId ,int userRecordId);

    List<UserRecordEntity> findByUserRecordId(int userRecordId);

    List<UserRecordEntity> findByTitleLikeAndShare(String title, int share);

    List<UserRecordEntity> findByTitleLikeAndShareAndSelected(String title, int share, int select);

    List<UserRecordEntity> findByUserIdAndShare(int userId, int share);

    List<UserRecordEntity> findByUserIdAndUserRecordIdAndShare(int userId ,int userRecordId, int share);

    // 分享曲线用户list
    @Query(value = "SELECT * FROM USER_RECORD WHERE share = 1 GROUP BY user_id", nativeQuery = true)
    List<UserRecordEntity> findGroupByUserId();

    // 精选曲线用户list
    @Query(value = "SELECT * FROM USER_RECORD WHERE share = 1 AND selected = 1 GROUP BY user_id", nativeQuery = true)
    List<UserRecordEntity> findGroupByUserIdSelect();

}
